/**
 * Utility helper functions implementation.
 */

#include "helpers.h"

#include <fstream>
#include <iostream>
#include <filesystem>
#include <stdexcept>

namespace utils {

void setup_logging(bool verbose) {
    if (verbose) {
        std::cout << "Verbose logging enabled" << std::endl;
    }
    // In a real implementation, this would configure a logging library
}

bool validate_file(const std::string& file_path) {
    try {
        std::filesystem::path path(file_path);
        return std::filesystem::exists(path) && std::filesystem::is_regular_file(path);
    } catch (const std::exception&) {
        return false;
    }
}

std::string read_file_safely(const std::string& file_path) {
    std::ifstream file(file_path);
    if (!file.is_open()) {
        throw std::runtime_error("Cannot open file: " + file_path);
    }
    
    std::string content;
    std::string line;
    while (std::getline(file, line)) {
        content += line + "\n";
    }
    
    file.close();
    return content;
}

void ensure_directory(const std::string& dir_path) {
    std::filesystem::path path(dir_path);
    std::filesystem::create_directories(path);
}

std::string get_file_extension(const std::string& file_path) {
    try {
        std::filesystem::path path(file_path);
        return path.extension().string();
    } catch (const std::exception&) {
        return "";
    }
}

} // namespace utils